#pragma once 
#include <iostream>
#include <string>
#include <cstdio>
#include <functional>


void serviceIO(int sock)
{
    char buffer[1024];
    while(true)
    {
        //暂时把读到的数据当字符串
        ssize_t n = read(sock,buffer,sizeof(buffer)-1);
        if(n > 0)
        {
            buffer[n] = 0;
            cout << "recv message: " << buffer << endl;
            
            string outbuffer = buffer;
            outbuffer += " server[echo]";
            write(sock,outbuffer.c_str(),outbuffer.size()); //多路转接
        }
        else if(n == 0)
        {
            // 代表Client退出
            logMessage(NORMAL,"client quit,me to!");
            break;
        }
    }
}

class Task
{
public:
    using fun_t = std::function<void(int)>;

public:
    Task()
    {}
    Task(int sock,fun_t func)
        :_sock(sock),_callback(func)
    {}
    void operator()()
    {
        _callback(_sock);

    }

    ~Task()
    {}
private:
    int _sock;
    fun_t _callback;
};
